项目目录结构如下,想要实现一个命令同时跑前端和后端,可以使用 concurrently
1 | . |
在项目根目录安装
1
npm i concurrently --save
修改
package.json
1
2
3
4
5
6"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"client": "npm start --prefix client",
"server": "nodemon ./db/index.ts",
"dev": "concurrently \"npm run server\" \"npm run client\""
}执行
1
2
3npm run client # 执行前端代码
npm run server # 执行后端代码
npm run dev # 同时执行前面两条代码